//
// Created by icezhang on 2021/9/8.
//

#ifndef DRON_TEST1_MYSQLSINGLETON_H
#define DRON_TEST1_MYSQLSINGLETON_H

#include "mysql.h"
#include "string"
#include "iostream"
using namespace std;
class MysqlSingleton {

private:

    int num_fields,i;
    MYSQL_RES *res;
    MYSQL_ROW row;
    MYSQL_FIELD *field;
    /*创建数据连接对象*/
    MYSQL *con = mysql_init(NULL);

    MysqlSingleton(){
        cout<<"Mysql Singleton init success"<<endl;

        if(con == NULL)
        {
            fprintf(stderr, "%s\n", mysql_error(con));
            exit(EXIT_FAILURE);
        }

        if(!mysql_real_connect(con, "bah.bodyta.com","root", "qhlk@2017", NULL, 13306, NULL,0))
        {
            fprintf(stderr, "%s\n", mysql_error(con));
            mysql_close(con);
            exit(EXIT_FAILURE);
        }
    }
    ~MysqlSingleton(){
        cout<<"Mysql Singleton destroy success"<<endl;
        mysql_close(con);
    }

public:
    static MysqlSingleton &GetInstance(){
        static MysqlSingleton instance;
        return instance;
    }
    string doSomething();



};


#endif //DRON_TEST1_MYSQLSINGLETON_H
